<?php

namespace App\Http\Requests\Backend\Setting;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class SettingchannelRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $method = $this->method();
        switch ($method){
            case 'POST':
                return [
                    'channel_code' => 'bail|required|unique:setting_channels',
                    'channel_name' => 'required',
                ];
                break;
            case "PUT":
                return [
                    'channel_code' => [Rule::unique('setting_channels')->ignore($this->route('channel')),],
                    'is_show_plan_table' => 'in:0,1',
                    'period_range' => 'json',
                ];
                break;
        }
    }

    public function messages()
    {
        return [
            'channel_code.required' => '请传递资方编号',
            'channel_code.unique' => '资方编号重复',
            'channel_name.required' => '请传递资方名称',
            'is_show_plan_table.in' => '请传递正确格式的类型',
            'period_range.json' => '请传递正确的json格式',
        ];
    }
}
